package ldh.text.util;

import javafx.fxml.FXMLLoader;

import java.io.IOException;
import java.net.URL;

public class FxmlNodeUtil {

    public static <T, C> FxmlNode<T, C> load(URL url) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(url);
        T node = fxmlLoader.load();
        C controller = fxmlLoader.getController();
        return new FxmlNode(node, controller);
    }

    public static class FxmlNode<T, C> {

        private T node;
        private C controller;

        public FxmlNode(T node, C controller) {
            this.node = node;
            this.controller = controller;
        }

        public T getNode() {
            return node;
        }

        public C getController() {
            return controller;
        }
    }
}
